// Strategy.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "Strategy.h"
#include "Const.h"
#include "Util.h"

#include "Equipo.h"

#include "EquipoEjemplo.h"	//	Custom team

#include <math.h>

char myMessage[200];

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}

//	Equipo de futbol
Equipo* equipo;

void Init();
void PredictBall ( Environment *env );
void PlayNormal(Environment *env );

// --------------------------------------------------------------------------------------------

extern "C" STRATEGY_API void Create ( Environment *env )
{	
	// allocate user data and assign to env->userData
	// eg. env->userData = ( void * ) new MyVariables ();
}

// --------------------------------------------------------------------------------------------

extern "C" STRATEGY_API void Destroy ( Environment *env )

{
	// free any user data created in Create ( Environment * )

	// eg. if ( env->userData != NULL ) delete ( MyVariables * ) env->userData;
}

// --------------------------------------------------------------------------------------------

extern "C" STRATEGY_API void Strategy ( Environment *env )
{
	PredictBall ( env );

	switch (env->gameState)
	{
	case PLAY:
		PlayNormal(env);
		break;
	case FREE_BALL:
		PlayNormal(env);
		break;
	case PLACE_KICK:
		PlayNormal(env);
		break;
	case PENALTY_KICK:
		switch (env->whosBall)
		{
		case ANYONES_BALL:
			PlayNormal(env);
			break;
		case BLUE_BALL:
			PlayNormal(env);
			break;
		case YELLOW_BALL:
			PlayNormal(env);
			break;
		}
		break;
	case FREE_KICK:
		switch (env->whosBall)
		{
		case ANYONES_BALL:
			PlayNormal(env);
			break;
		case BLUE_BALL:
			PlayNormal(env);
			break;
		case YELLOW_BALL:
			PlayNormal(env);
			break;
		}
		break;
	case GOAL_KICK:
		switch (env->whosBall)
		{
		case ANYONES_BALL:
			PlayNormal(env);
			break;
		case BLUE_BALL:
			PlayNormal(env);
			break;
		case YELLOW_BALL:
			PlayNormal(env);
			break;
		}
		break;
	}
	
	sprintf(myMessage, " ");
	env->display = myMessage; 

}

// --------------------------------------------------------------------------------------------

void Init() {
	
	equipo = new EquipoEjemplo();
	equipo->AddPlayers();
}

//------------------------------------------------------------------------------------------------

void PredictBall ( Environment *env )
{
	double dx = env->currentBall.pos.x - env->lastBall.pos.x;
	double dy = env->currentBall.pos.y - env->lastBall.pos.y;
	env->predictedBall.pos.x = env->currentBall.pos.x + dx;
	env->predictedBall.pos.y = env->currentBall.pos.y + dy;
}


// =====================================================================
// J U G A D A S   E S P E C I A L E S		//K27
// =====================================================================

void PlayNormal( Environment *env )
{
	equipo->Update(env);
}
